<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="com.wlcorp.forcazamis.domain.storageassign.StorageAssign" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.wlcorp.forcazamis.domain.storageassign.StorageAssignSample" %>
<%@ page import="com.wlcorp.forcazamis.domain.system.Staff" %>
<%@ page import="com.wlcorp.forcazamis.sys.util.SessionValue" %>
<%@ page import="com.wlcorp.forcazamis.sys.util.AppConstant" %>

<%
	StorageAssign storageAssign = (StorageAssign)request.getAttribute("storageAssign");
	Staff staff = SessionValue.getInstance(request).getStaff();
%>
<html>
<head>
	<title>样品调拨单信息更新</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Cache-Control" content="no-cache"><meta http-equiv="Expires" content="0">
	<link href="${pageContext.request.contextPath}/css/css.css" rel=stylesheet>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/button_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/form_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/table_css.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/pagetitle_css.css" type="text/css">
	<script language="javascript" src="${pageContext.request.contextPath}/script/validator.js"></script>
	<script language="javascript" src="${pageContext.request.contextPath}/script/calendartime.js"></script>
	<script language="javascript" src="${pageContext.request.contextPath}/script/ajax.js"></script>
	<script type="text/javascript">
		function doSave(){
			var inputArray = document.forms["storageAssignForm"].getElementsByTagName("input");
			for(i = 0;i < inputArray.length;i++){
				if("assignCount" == inputArray[i].name && "text" == inputArray[i].type && inputArray[i].value.length > 0 && parseInt(inputArray[i].value) <= 0){
					alert("数量必须大于0！");
					return;
				}
			}
			
			document.forms["storageAssignForm"].submit();
		}
		function baseInfoEdit(storageAssignId){
			window.location = "${pageContext.request.contextPath}/storageassign/storageAssignManager.do?method=getStorageAssign&storageAssignId=" + storageAssignId;
		}
		
		function selectNewSubSample(){
			var returnValue = window.showModalDialog("${pageContext.request.contextPath}/storagein/storageInManager.do?method=selectSubSampleListTop"
				,window,"dialogHeight:400px;dialogWidth:580px;center:yes;help:no;resizable:no;status:no;");
			//var returnValue = window.open("${pageContext.request.contextPath}/storageassign/storageAssignManager.do?method=selectSubSampleListTop");
			
			if(returnValue && null != returnValue){
				var table = document.getElementById("subSampleTbody");
				for(i = 0;i < returnValue.length;i++){
					appendRow(table,returnValue[i]);
				}
			}
		}
		
		function deleteRow(tr){
			if(confirm("确定删除？")){
				var table = document.getElementById("subSampleTbody");
				table.removeChild(tr);
			}
		}
		
		function appendRow(table,subSample){
          var tr = document.createElement('<tr id="' + subSample["subSampleId"] + '" bgcolor="#ffffff">');
          var td = document.createElement('<td style="visibility:hidden;display:none">');
          td.innerHTML = '<input type="hidden" name="subSampleId" value="' + subSample["subSampleId"] + '"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = subSample["sampleCode"];
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = subSample["size"];
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = subSample["plateColor"];
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = subSample["ccolorDesc"];
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="assignCount" value="0" maxlength="10" onkeyup="getTotalPrice(document.getElementById(\'' + subSample["subSampleId"] + '\'))"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="price" value="0.00" maxlength="10" onkeyup="getTotalPrice(document.getElementById(\'' + subSample["subSampleId"] + '\'))"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="totalPrice" value="0.00" maxlength="10" readOnly/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<input class="input" type="text" name="memo" value="" maxlength="100"/>';
          tr.appendChild(td);
          td = document.createElement('<td>');
          td.innerHTML = '<a href="javascript:deleteRow(document.getElementById(\'' + subSample["subSampleId"] + '\'))">删除</a>';
          tr.appendChild(td);
          table.insertBefore(tr,table.rows[table.rows.length - 1]);
        }
        
        function getTotalPrice(tr){
        	var totalPriceTxt = tr.cells[7].getElementsByTagName("input")[0];
        	var priceTxt = tr.cells[6].getElementsByTagName("input")[0];
        	var count = tr.cells[5].getElementsByTagName("input")[0];
        	totalPriceTxt.value = parseFloat(priceTxt.value) * parseFloat(count.value);
        }
        
        function selectAll(){
        	var table = document.getElementById("subSampleTbody");
        	var rows = table.rows;
        	for(i = 1;i < rows.length - 2;i++){
        		var checkbox = rows[i].cells[0].getElementsByTagName("input")[0];
        		checkbox.checked = true;
        	}
        }
        
        function withDrawStorageAssign(id){
        	if(confirm("确定退单？")){
        		window.location = "${pageContext.request.contextPath}/storageassign/storageAssignManager.do?method=withDrawStorageAssign&storageAssignId=" + id;
        	}
        }
        
        function doSubmitConfirm(){
        	<%
        		if(null == storageAssign.getStorageAssignSampleSet() || storageAssign.getStorageAssignSampleSet().size() < 1){
        			out.print("alert('请选择调拨样品并保存！');return;");
        		}
        	%>
			var sUrl = "${pageContext.request.contextPath}/confirm/confirmManager.do?method=submitConfirm"
				+ "&confirmType=<%=AppConstant.CONFIRM_TYPE_ASSIGN_STORAGE%>&itemId=${storageAssign.storageAssignId}";
			ajaxRead(sUrl,function(obj){
				var result = obj.responseText;
				alert(result);
				document.getElementById("submitConfirmBtn").disabled = true;
			});
		}
	</script>
</head>
<body>
<center>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="30">
	<tr> 
	  <td width="22" class="page_titlebar_head">&nbsp;</td>
	  <td class="page_titlebar_bg" width="981">样品调拨单编辑</td>
	</tr>
</table>
<table width="850" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" class="table_bgcolor">
      <tr> 
        <td align="right" valign="middle"> 
          <input class="button_common" type=button name="submitConfirmBtn" value="提交审批" style="font-size:9pt" onClick="javascript:doSubmitConfirm()" id="submitConfirmBtn" <%if(AppConstant.ASSIGN_STATE_CONFIRMING == storageAssign.getState() || AppConstant.ASSIGN_STATE_CONFIRMED == storageAssign.getState() || null != storageAssign.getConfirm()){out.print("disabled");}%>>
        </td>
      </tr>
</table>
<table width="850" class="InputFrameMain" cellspacing="0" cellpadding="0" border="0" height="100">
  <tr> 
    <td colspan="4" class="table_unfold_titlebar_small_bg">&nbsp;&nbsp;<b>样品调拨单</b></td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%">调出仓库仓库：</td>
		<td width="30%">${storageAssign.assignFromDepot.depotName}
		</td>
		<td class="table_label" width="20%">调入仓库仓库：</td>
		<td width="30%">${storageAssign.assignToDepot.depotName}
		</td>
  </tr>
  <tr>
  	<td class="table_label" width="20%">调拨人：</td>
	<td width="30%">${storageAssign.submiter.staffName}
	</td>
	<td class="table_label" width="20%">调拨时间：</td>
	<td width="30%">${storageAssign.assignDate}
	</td>
  </tr>
  <tr class="InputFrameLine">
        <td class="table_label" width="20%" id="memo_TEXT">备注：</td>
		<td width="80%" colspan="5">${storageAssign.memo}
		</td>
  </tr>
  <tr class="InputFrameLine">
  	<td width="100%" colspan="6" align="center"><input type="button" class="button_common_5" name="baseInfoButton" value="基本信息编辑" onclick="javascript:baseInfoEdit('${storageAssign.storageAssignId}')"/>
  	<td>
  </tr>
</table>
<form name="storageAssignForm" method="POST" action="${pageContext.request.contextPath}/storageassign/storageAssignManager.do?method=modifyStorageAssignDetail">
<input type="hidden" name="storageAssignId" value="${storageAssign.storageAssignId}"/>
<table id="" width="850" border="0" cellspacing="1" cellpadding="0" bgcolor="#999999">
	  <tbody id="subSampleTbody">
      <tr bgcolor="#E7E7E7">
      	<td style="visibility:hidden;display:none">样品ID</td>
        <td>样品编号</td>
        <td>尺寸</td>
        <td>电镀色号</td>
        <td>颜色描述</td>
        <td>数量</td>
        <td>单价</td>
        <td>金额</td>
        <td>备注</td>
        <td>编辑</td>
      </tr>
      <%
      	//System.out.println(storageAssign.getStorageAssignSampleSet().size());
      	if(null != storageAssign.getStorageAssignSampleSet() && storageAssign.getStorageAssignSampleSet().size() > 0){
      		for(Iterator iter = storageAssign.getStorageAssignSampleSet().iterator();iter.hasNext();){
      			StorageAssignSample storageAssignSample = (StorageAssignSample)iter.next();
      			
      %>
      <tr id="<%=storageAssignSample.getId()%>" bgcolor="#ffffff">
      	<td style="visibility:hidden;display:none"><input type="hidden" name="subSampleId" value="<%=storageAssignSample.getSubSample().getSubSampleId()%>"/></td>
      	<td><%=storageAssignSample.getSubSample().getParentSample().getSampleCode()%></td>
        <td><%=storageAssignSample.getSubSample().getSize()%></td>
        <td><%=storageAssignSample.getSubSample().getPlateColor()%></td>
        <td><%=storageAssignSample.getSubSample().getCcolorDesc()%></td>
        <td><input class="input" type="text" name="assignCount" value="<%=storageAssignSample.getAssignCount()%>" maxlength="20" onkeyup="getTotalPrice(document.getElementById('<%=storageAssignSample.getId()%>'))"/></td>
        <td><input class="input" type="text" name="price" value="<%=storageAssignSample.getPrice()%>" maxlength="20" onkeyup="getTotalPrice(document.getElementById('<%=storageAssignSample.getId()%>'))"/></td>	
        <td><input class="input" type="text" name="totalPrice" value="<%=storageAssignSample.getTotalPrice()%>" maxlength="20" readOnly/></td> 
        <td><input class="input" type="text" name="memo" value="<%=storageAssignSample.getMemo()%>" maxlength="100"/></td>	           
        <td>
        <%
			if(null == storageAssign.getState() || AppConstant.ASSIGN_STATE_SUBMITED == storageAssign.getState()){
		%>
        <a href="javascript:deleteRow(document.getElementById('<%=storageAssignSample.getId()%>'))">删除</a>
        <%}%></td>
	  </tr>
	  <%}}
		if(null == storageAssign.getState() || AppConstant.ASSIGN_STATE_SUBMITED == storageAssign.getState()){
	  %>
	  <tr bgcolor="#ffffff">
        <td colspan="10" align="center"><input type="button" name="selectNewSubSampleSampleButton" value="选择样品子类" onclick="selectNewSubSample()"/>&nbsp;
        <input type="button" name="saveButton" value="保存" onclick="doSave()"/></td>
	  </tr>
	  <%}%>
	  </tbody>
</table>
</form>
</center>
${message}
</body>
</html>
